<!--包含头部文件-->
{include file="public/header" /}
<style>
    #inputBox{
        width: 100%;
        height: 40px;
        border: 1px solid cornflowerblue;
        color: cornflowerblue;
        border-radius: 20px;
        position: relative;
        text-align: center;
        line-height: 40px;
        overflow: hidden;
        font-size: 16px;
    }
    #inputBox input{
        width: 114%;
        height: 40px;
        opacity: 0;
        cursor: pointer;
        position: absolute;
        top: 0;
        left: -14%;
    }
    #imgBox{
        text-align: left;
    }
    .imgContainer{
        display: inline-block;
        width: 32%;
        height: 150px;
        margin-left: 1%;
        border: 1px solid #666666;
        position: relative;
        margin-top: 30px;
        box-sizing: border-box;
    }
    .imgContainer img{
        width: 100%;
        height: 150px;
        cursor: pointer;
    }
    .imgContainer p{
        position: absolute;
        bottom: -1px;
        left: 0;
        width: 100%;
        height: 30px;
        background: black;
        text-align: center;
        line-height: 30px;
        color: white;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        display: none;
    }
    .imgContainer:hover p{
        display: block;
    }
    .lubo_pic{float: left;border: 1px dashed #000000;margin: 0 auto;cursor:pointer;text-align: center;background-image: url("__STATIC__/images/background_image.png")}
</style>
<body>
<article class="page-container">
    <form class="form form-horizontal" action="" method="post" id="form-carousel-edit">
        <input type="hidden" class="input-text" value="{$data.carousel_id}" name="carousel_id"/>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$data.title}" placeholder="请输入轮播标题" id="title" name="title"/>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>轮播展示位：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="position" id="position" class="select" style="width: auto">
                    <option value="0" {if condition="$data['position'] eq 0"}selected {/if}>请选择展示位置</option>
                    <option value="1" {if condition="$data['position'] eq 1"}selected {/if}>首页顶部</option>
                    <option value="2" {if condition="$data['position'] eq 2"}selected {/if}>首页中部</option>
                </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
            <div class="formControls col-xs-8 col-sm-8">
                <span class="select-box" style="width: auto">
                    <select name="cate" id="select_cate" class="select" style="width: auto">
                    <option value="0" {if condition="$data['cate'] eq 0"}selected {/if}>请选择轮播类型</option>
                    <option value="2" {if condition="$data['cate'] eq 2"}selected {/if}>网页链接</option>
                    <option value="3" {if condition="$data['cate'] eq 3"}selected {/if}>专题</option>
                    <option value="4" {if condition="$data['cate'] eq 4"}selected {/if}>商品</option>
                </select>
                </span>
            </div>
        </div>

        {if condition="$data['cate'] == 2"}
        <div class="row cl" id="item_content">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span><span id="tex">网址链接：</span></label>
            <div class="formControls col-xs-6 col-sm-6" id="item_content_div">
                {$data['str']}
            </div>
        </div>

        {elseif condition="$data['cate'] == 4"}

        <div class="row cl" id="item_content">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span><span id="tex">商品id：</span></label>
            <div class="formControls col-xs-6 col-sm-6" id="item_content_div">
                <input type="text"class="input-text"  name="item_content" value="{$data['item_content']}" placeholder="请输入商品id">
            </div>
        </div>
        <div class="row cl" id="couponurl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券链接：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$data['couponurl']}" placeholder="请输入优惠券链接，没有则放空" name="couponurl"/>
            </div>
        </div>
        {/if}
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>店铺图片：</label>
            <div class="formControls col-xs-5 col-sm-5">
                <div class="lubo_pic" onclick="img_div(this)">
                    <img src="{$data.host_image}" style="width: 335px;height: 82px">
                </div>
                <input id="upload_img" name="activity_img" accept="image/*" onchange="uploadImgFile(this)" type="file" style="display: none"/>
                <input name="image" value="{$data.image}" type="hidden" />
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>开始时间：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text"class="input-text start_time"  id="start_time" name="start_time" value="{$data.start_time|date='Y-m-d H:i:s', ###}" >
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>结束时间：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text"class="input-text end_time"  id="end_time" name="end_time" value="{$data.end_time|date='Y-m-d H:i:s', ###}">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input name="status" value="1" type="radio" id="status-1" {if condition="$data['status'] eq 1"}checked {/if}>
                    <label for="status-1">启用</label>
                </div>
                <div class="radio-box">
                    <input type="radio" value="0" id="status-2" name="status" {if condition="$data['status'] eq 0"}checked {/if}>
                    <label for="status-2">关闭</label>
                </div>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--包含footer文件-->
{include file="public/footer" /}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__STATIC__/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="__STATIC__/layui/layui.all.js"></script>

<script type="text/javascript">

    /*地图定位*/
    function map(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    //点击图片上传
    function img_div(e) {
        $("#upload_img").click()
    }
    //    上传图片
    function uploadImgFile(even) {
        var id = even.id;
        $.ajaxFileUpload
        (
            {
                url: '{:url("Upload/img_upload")}',//需要链接到服务器地址
                secureuri: false,
                fileElementId: id,
                dataType: 'json',
                success: function (data)  //服务器成功响应处理函数
                {
                    var path = data.data.path;
                    var host_path = data.data.host_path;
                    $("#"+id).next().val(path);
                    $("#"+id).prev().children(':first').attr('src',host_path);
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert(e);
                }
            }
        )
        return false;

    }

    $(function () {
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-carousel-edit").validate({
            rules:{
                title:{
                    required:true,
                },
                item_content:{
                    required:true,
                },
                start_time:{
                    required:true,
                },
                end_time:{
                    required:true,
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var arr = new FormData(document.getElementById("form-carousel-edit"));
                $.ajax({
                    url:"{:url('operate/carousel_edit')}",
                    type:"post",
                    data:arr,
                    async: true,
                    processData: false,
                    contentType: false,
                    dataType:"json",
                    success:function (data) {
                        if (data.code == 200){
                            layer.alert('编辑成功',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                                ,yes:function(){
                                    layer.closeAll();
                                    parent.location.reload();
                                }
                            })
                        }else {
                            layer.alert('编辑失败'+data.msg+'',{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                            })
                        }

                    },
                    error:function () {
                        layer.alert('编辑失败',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    }
                })

            }
        });
        //根据选择的类型展示相应的表格
        $("#select_cate").change(function () {
            var ss = $(this).children('option:selected').val();
            var html;
            if (ss == 1) {
                $('#item_content').css('display','block');
                $('#couponurl').css('display','none');
                $("#tex").text('店铺:')
                $.ajax({
                    type: 'POST',
                    url: "{:url('shop/ajax_getshops')}",
                    dataType: 'json',
                    success: function(data){
                        if (data.code == 200){
                            var str;
                            for (var i =0;i<data.data.length;i++){
                                str += '<option value="'+data.data[i].id+'">'+data.data[i].shop_name+'</option>'
                            }
                            html = ' <span class="select-box" style="width: auto"> <select name="item_content" class="select" style="width: auto">'+ str + '</select></span>';
                            $('#item_content_div').html(html)
                        }else {
                            layer.alert(data.msg,{
                                skin: 'layui-layer-molv' //样式类名 自定义样式
                                ,closeBtn: 0  // 是否显示关闭按钮
                                ,anim: 1 //动画类型
                                ,btn: '确认'//按钮
                                ,icon: 6  // icon
                            })
                        }
                    },
                    error:function(data) {
                        layer.alert('请求错误',{
                            skin: 'layui-layer-molv' //样式类名 自定义样式
                            ,closeBtn: 0  // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: '确认'//按钮
                            ,icon: 6  // icon
                        })
                    },
                });

            } else if (ss == 2) {
                $('#item_content').css('display','block');
                $('#couponurl').css('display','none');
                $("#tex").text('网址链接:')
                html = '<input type="text"class="input-text"  name="item_content" value="" placeholder="请输入要链接的网址">';
                $('#item_content_div').html(html)
            }else if (ss == 4) {
                $('#item_content').css('display','block');
                $("#tex").text('商品id:')
                html = '<input type="text"class="input-text"  name="item_content" value="" placeholder="请输入商品id">';
                $('#item_content_div').html(html)
                $("#item_content").after('<div class="row cl" id="couponurl"><label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券链接：</label><div class="formControls col-xs-6 col-sm-6"><input type="text" class="input-text" value="" placeholder="请输入优惠券链接，没有则放空" name="couponurl"/></div></div>');
            } else if (ss == 3) {
                $('#item_content').css('display', 'none');
                $('#couponurl').css('display', 'none');
            }
        });

        //时间插件调取
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //常规用法
            laydate.render({
                elem: '.start_time'
                ,type: 'datetime'
            });
            //常规用法
            laydate.render({
                elem: '.end_time'
                ,type: 'datetime'
            });
        });

    });
</script>

<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>